package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.annotation.LogAnno;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.service.CheckInfoService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/checkinfo")
public class CheckInfoController {
    @Reference
    private CheckInfoService checkInfoService;

    @LogAnno(operateType = "分页查询体检信息")
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return checkInfoService.findPage(queryPageBean);
    }
    @LogAnno(operateType = "查询检查组和检查项及内容信息")
    @RequestMapping("/findAllCheckgroupAndCheckitem")
    public Result findAllCheckgroupAndCheckitem(Integer orderId){
        List<Map<String, Object>> result = checkInfoService.findAllCheckgroupAndCheckitem(orderId);
        return new Result(true,"查询检查组和检查项及内容信息成功",result);
    }

    @LogAnno(operateType = "更新体检信息")
    @RequestMapping("/update")
    public Result update( @RequestBody List<Map<String,Object>> checkgroupList){
        try {
            checkInfoService.update(checkgroupList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,"体检信息更新失败");
        }
        return new Result(true,"体检信息更新成功");
    }
    @LogAnno(operateType = "完成体检信息")
    @RequestMapping("/complete")
    public Result complete( @RequestBody List<Map<String,Object>> checkgroupList){
        try {
            checkInfoService.complete(checkgroupList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,"体检信息完成失败");
        }
        return new Result(true,"体检信息完成成功");
    }

    @LogAnno(operateType = "分页查询体检信息")
    @RequestMapping("/reportFindPage")
    public PageResult reportFindPage(@RequestBody QueryPageBean queryPageBean){
        return checkInfoService.reportFindPage(queryPageBean);
    }
}
